package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.service.IEwmsOutWarehouseService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsOutWarehouseVo;
import ewms.bo.EwmsOutWarehouseQueryBo;
import ewms.bo.EwmsOutWarehouseAddBo;
import ewms.bo.EwmsOutWarehouseEditBo;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 危废出库Controller
 *
 * @author zhaoxiaochun
 * @date 2022-02-16
 */
@Api(value = "危废出库控制器", tags = {"危废出库管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/outWarehouse")
public class EwmsOutWarehouseController extends BaseController {

    private final IEwmsOutWarehouseService iEwmsOutWarehouseService;

    /**
     * 查询危废待出库列表
     */
    @ApiOperation("查询危废出库列表")
    @PreAuthorize("@ss.hasPermi('business:outWarehouse:list')")
    @GetMapping("/PreOutList")
    public TableDataInfo<EwmsOutWarehouseVo> preOutList(@Validated EwmsOutWarehouseQueryBo bo) {
        return iEwmsOutWarehouseService.selectPagePreOutWarehouseList(bo);
    }

    /**
     * 导出危废待出库列表
     */
    @ApiOperation("导出危废出库列表")
    @PreAuthorize("@ss.hasPermi('business:outWarehouse:export')")
    @Log(title = "危废出库", businessType = BusinessType.EXPORT)
    @GetMapping("/PreOutExport")
    public AjaxResult<EwmsOutWarehouseVo> preOutExport(@Validated EwmsOutWarehouseQueryBo bo) {
        List<EwmsOutWarehouseVo> list = iEwmsOutWarehouseService.selectPreOutWarehouseList(bo);
        ExcelUtil<EwmsOutWarehouseVo> util = new ExcelUtil<EwmsOutWarehouseVo>(EwmsOutWarehouseVo.class);
        return util.exportExcel(list, "危废出库");
    }

	/**
	 * 查询危废出库列表
	 */
	@ApiOperation("查询危废出库列表")
	@PreAuthorize("@ss.hasPermi('business:outWarehouse:list')")
	@GetMapping("/list")
	public TableDataInfo<EwmsOutWarehouseVo> list(@Validated EwmsOutWarehouseQueryBo bo) {
		return iEwmsOutWarehouseService.selectPageOutWarehouseList(bo);
	}

	/**
	 * 导出危废出库列表
	 */
	@ApiOperation("导出危废出库列表")
	@PreAuthorize("@ss.hasPermi('business:outWarehouse:export')")
	@Log(title = "危废出库", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<EwmsOutWarehouseVo> export(@Validated EwmsOutWarehouseQueryBo bo) {
		List<EwmsOutWarehouseVo> list = iEwmsOutWarehouseService.selectOutWarehouseList(bo);
		ExcelUtil<EwmsOutWarehouseVo> util = new ExcelUtil<EwmsOutWarehouseVo>(EwmsOutWarehouseVo.class);
		return util.exportExcel(list, "危废出库记录");
	}

    /**
     * 获取危废出库详细信息
     */
    @ApiOperation("获取危废出库详细信息")
    @PreAuthorize("@ss.hasPermi('business:outWarehouse:query')")
    @GetMapping("/{outWarehouseId}")
    public AjaxResult<EwmsOutWarehouseVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("outWarehouseId") Long outWarehouseId) {
        return AjaxResult.success(iEwmsOutWarehouseService.queryById(outWarehouseId));
    }

    /**
     * 新增危废出库
     */
    @ApiOperation("新增危废出库")
    @PreAuthorize("@ss.hasPermi('business:outWarehouse:add')")
    @Log(title = "危废出库", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsOutWarehouseAddBo bo) {
    	return toAjax(iEwmsOutWarehouseService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改危废出库
     */
    @ApiOperation("修改危废出库")
    @PreAuthorize("@ss.hasPermi('business:outWarehouse:edit')")
    @Log(title = "危废出库", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsOutWarehouseEditBo bo) {
        return toAjax(iEwmsOutWarehouseService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除危废出库
     */
    @ApiOperation("删除危废出库")
    @PreAuthorize("@ss.hasPermi('business:outWarehouse:remove')")
    @Log(title = "危废出库" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{outWarehouseIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] outWarehouseIds) {
        return toAjax(iEwmsOutWarehouseService.deleteWithValidByIds(Arrays.asList(outWarehouseIds), true) ? 1 : 0);
    }
}
